package com.fingard.dsp.bank.directbank.ybt11;

import java.sql.Connection;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

import com.fingard.FGBiz;
import com.fingard.db.JDBCHelper;
import com.fingard.diagnostics.LogHelper;
import com.fingard.dsp.bank.directbank.DirectBase;

public class YBT11Base extends DirectBase {
	/**
	 * 数据批量插入中间表
	 * 
	 * @param params 请求数据明细
	 * @param p_sb 日志信息
	 * @return
	 */
	public boolean saveEachRecords(LinkedList<Object> params, StringBuilder p_sb) {
		if (FGBiz.dspCenter.dspSet.dbConnectionSet != null) {
			try {
				Connection dbConn = null;

				try {
					dbConn = FGBiz.dspCenter.dspSet.dbConnectionSet.getConnection();

					JDBCHelper.update(dbConn,
							"insert into YBT_BATCH_FILES(URID, REQBATCHNO, ASKNUMBER, ABSTRACT, PAYSENTDATE, SOURCENOTECODE, TRADEDIRECTION, PAYTYPE, BANKCODE, CROPSTANDAREA, "
									+ "CNAPS, YBTACCOUNT, CUSACCOUNT, CUSNAME, PAYMONEY, ISPRIVATE, PAYPERIOD, OPPSTANDAREA, CARDTYPE, CERTTYPE, CERTNUMBER, PHONE, CONTRACTNO, POLICYNO, CURRENCY,"
									+ " USEOF, DESCRIPTION, PAYSTATE, PAYINFO, PAYINFOCODE, BANKERRORCODE, SENDRESULT, SENDTIME, BACKRESULT, BACKTIME, CREATEDDATE, CREATEDBY, MODIFIEDDATE, "
									+ "MODIFIEDBY, ROWVERSION, BANKSENDFILENAME, BANKBACKFILENAME, RESERVED1, RESERVED2, RESERVED3) "
									+ "values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)",
							params.toArray());
					return true;
				} catch (Exception ex) {
					p_sb.append(LogHelper.getStackTrace(ex));
					ex.printStackTrace();
				} finally {
					if (dbConn != null) {
						dbConn.close();
					}
				}
			} catch (Exception ex) {
				p_sb.append(LogHelper.getStackTrace(ex));
				ex.printStackTrace();
			}
		} else {
			p_sb.append("数据库连接未配置或有误");
		}
		return false;
	}

	/**
	 * 从中间表查询批量结果明细数据
	 * 
	 * @param reqSeqID 批次号
	 * @return 批次结果明细数据
	 * @throws Exception
	 */
	public List<Map<String, Object>> getResultRecords(String reqSeqID) throws Exception {
		if (FGBiz.dspCenter.dspSet.dbConnectionSet != null) {
			Connection dbConn = null;
			try {
				dbConn = FGBiz.dspCenter.dspSet.dbConnectionSet.getConnection();

				String sqlSelect = "select * from YBT_BATCH_FILES where reqbatchno = ?";
				List<Map<String, Object>> seqList = JDBCHelper.execQuery(dbConn, sqlSelect, new Object[] { reqSeqID });
				return seqList;
			} catch (Exception ex) {
				throw (ex);
			} finally {
				if (dbConn != null) {
					dbConn.close();
				}
			}
		} else {
			throw new Exception("数据库连接未配置或有误");
		}
	}
}
